﻿/*************************************************************************************************
 * A small tool that can make jquery.validate works with Bottstrap
 * Author : Jerry Cai
 * Date: 2.2.2013
 *************************************************************************************************/


$.validator.setDefaults({
    highlight: function (element, errorClass, validClass) {
        var $element;
        if (element.type === 'radio') {
            $element = this.findByName(element.name);
        } else {
            $element = $(element);
        }
        $element.addClass(errorClass).removeClass(validClass);
        // add the bootstrap error class
        $element.parents("div.control-group").addClass("error");
    },

    unhighlight: function (element, errorClass, validClass) {
        var $element;
        if (element.type === 'radio') {
            $element = this.findByName(element.name);
        } else {
            $element = $(element);
        }
        $element.removeClass(errorClass).addClass(validClass);
        // remove the bootstrap error class
        $element.parents("div.control-group").removeClass("error");
    },

    errorPlacement: function(error, element) {                        
        error.appendTo(element.next() );                             
    }, 
});

